#include "SPI.h"

int SPI::begin()
{
    if (is_init)
        return 1;
    if (mode == SPI_Mode_Hard)
    {
        spi_hard = spi_hard_init(spi_hard.spi, spi_hard.speed, spi_hard.c_mode);
    }
    is_init = 1;
    return 1;
}

int SPI::end()
{
    return 1;
}

void SPI::loadSlave(Pin_enum cs_pin)
{
    spi_hard.cs = cs_pin;
}

void SPI::deloadSlave()
{
    spi_hard.cs = Pin_null;
}

size_t SPI::write(uint8_t byte)
{
    return spi_hard_write_data(&spi_hard, byte);
}

size_t SPI::write(const uint8_t *buffer, size_t size)
{
    return spi_hard_write_datas(&spi_hard, buffer, size);
}

size_t SPI::write(const uint8_t data, size_t count)
{
    return spi_hard_fill_datas(&spi_hard, data, count);
}
uint16_t SPI::read()
{
    return spi_hard_receive_data(&spi_hard);
}
size_t SPI::read(uint8_t *buffer, size_t size)
{
    return spi_hard_receive_datas(&spi_hard, buffer, size);
}
/*************************************/
size_t SPI::write16(uint16_t byte)
{
    return spi_hard_write_data16(&spi_hard, byte);
}

size_t SPI::write16(const uint16_t *buffer, size_t size)
{
    return spi_hard_write_data16s(&spi_hard, buffer, size);
}

size_t SPI::write16(const uint16_t data, size_t count)
{
    return spi_hard_fill_data16s(&spi_hard, data, count);
}
uint16_t SPI::read16()
{
    return spi_hard_receive_data16(&spi_hard);
}
size_t SPI::read16(uint16_t *buffer, size_t size)
{
    return spi_hard_receive_data16s(&spi_hard, buffer, size);
}
